import gzip
import bz2

# 想读写一个gzip或bz2格式的压缩文件
def demo_1():
    with gzip.open('../temp/gzip_file.gz', 'rt') as f:
        text = f.read()
        print(text)
        f.close()

def demo_2():
    with bz2.open('../temp/bz2_file.bz2', 'rt') as f:
        text = f.read()
        print(text)
        f.close()

def demo_3():
    with gzip.open('../temp/gzip_file.gzip', 'wt') as f:
        f.write("gzip file")
        f.close()

def demo_4():
    with bz2.open('../temp/bz2_file.bz2', 'wt') as f:
        f.write("bz2 file")
        f.close()

if __name__ == '__main__':
    # demo_1()
    # demo_2()
    demo_3()
    # demo_4()